from marshmallow import fields

from gis.common.django_ext.forms import (
    BaseSchema,
    PaginationSchema,
    EnumField,
    GenericList,
)
from itpay.core.agency.const import (
    ReceiptType,
    ReceiptMethodType,
    BankCode,
    PayType,
    PayMethodType,
)
from itpay.core.user.const import UserLevel


class ReceiptAddressQuotaSchema(BaseSchema):
    amount = fields.Integer(required=True)
    real_amount = fields.Integer(missing=0)
    qr_code = fields.String()


class AddReceiptAddressSchema(BaseSchema):
    receipt_type = EnumField(ReceiptType, required=True)
    receipt_method = EnumField(ReceiptMethodType, required=True)
    account = fields.String(allow_none=True)
    account_qr_code = fields.String(allow_none=True)
    nickname = fields.String(allow_none=True)
    ali_zkl = fields.String(allow_none=True)
    qr_code = fields.String(allow_none=True)
    mch_name = fields.String(allow_none=True)
    can_huabei = fields.Boolean(allow_none=True)
    can_credit = fields.Boolean(allow_none=True)
    can_person = fields.Boolean(allow_none=True)
    first_name = fields.String(allow_none=True)
    last_name = fields.String(allow_none=True)
    bank_code = EnumField(BankCode, allow_none=True)
    bank_branch = fields.String(allow_none=True)
    phone = fields.String(allow_none=True)
    auto_arrival = fields.Boolean(required=True)
    min_user_level = EnumField(UserLevel, required=True)
    daily_amount_limit = fields.Integer(allow_none=True)
    status = fields.Boolean(required=True)
    remark = fields.String(allow_none=True)


class UpdateReceiptAddressSchema(BaseSchema):
    account = fields.String(allow_none=True)
    account_qr_code = fields.String(allow_none=True)
    nickname = fields.String(allow_none=True)
    ali_zkl = fields.String(allow_none=True)
    qr_code = fields.String(allow_none=True)
    mch_name = fields.String(allow_none=True)
    can_huabei = fields.Boolean(allow_none=True)
    can_credit = fields.Boolean(allow_none=True)
    can_person = fields.Boolean(allow_none=True)
    first_name = fields.String(allow_none=True)
    last_name = fields.String(allow_none=True)
    bank_code = EnumField(BankCode, allow_none=True)
    bank_branch = fields.String(allow_none=True)
    phone = fields.String(allow_none=True)
    auto_arrival = fields.Boolean(required=True)
    min_user_level = EnumField(UserLevel, required=True)
    daily_amount_limit = fields.Integer(allow_none=True)
    status = fields.Boolean(required=True)
    remark = fields.String(allow_none=True)


class QueryReceiptAddressSchema(PaginationSchema):
    id = fields.Integer(allow_none=True)
    agency_id = fields.Integer(allow_none=True)
    agency_name = fields.String(allow_none=True)
    pay_types = GenericList(EnumField(PayType, allow_none=True))
    pay_method = EnumField(PayMethodType, allow_none=True)
    receipt_type = EnumField(ReceiptType, allow_none=True)
    receipt_method = EnumField(ReceiptMethodType, allow_none=True)
    auto_arrival = fields.Boolean(allow_none=True)
    status = fields.Boolean(allow_none=True)
    mch_id = fields.Integer(allow_none=True)
    reached_daily_limit = fields.Boolean(allow_none=True)
    available = fields.Boolean(allow_none=True)
    receipt_name = fields.String(allow_none=True)
    min_user_level = EnumField(UserLevel, allow_none=True)


class UpdateReceiptAddressStatusSchema(BaseSchema):
    status = fields.Boolean(required=True)
